#include "GUIDataFluidWidget.h"
#include "ui_GUIDataFluidWidget.h"

#include "FITK_Interface/FITKInterfaceCustomData/FITKCDDataFluid.h"
#include "FITK_Kernel/FITKCore/FITKOperatorRepo.h"
#include "OperatorsInterface/TreeEventOperator.h"

using namespace GUI;

GUIDataFluidWidget::GUIDataFluidWidget(Interface::FITKCDDataFluid* obj, EventOper::ParaWidgetInterfaceOperator* oper, QWidget* parent) :
	GUIWidgetBase(parent), _oper(oper), _obj(obj)
{
	_ui = new Ui::GUIDataFluidWidget();
	_ui->setupUi(this);

	init();
}

GUIDataFluidWidget::~GUIDataFluidWidget()
{
	if (_ui) {
		delete _ui;
		_ui = nullptr;
	}
}

void GUIDataFluidWidget::init()
{
	_ui->comboBox_Material->addItems(QStringList() << "water");

	setDataToWidget();
}

void GUIDataFluidWidget::setDataToWidget()
{
	_ui->lineEdit_Name->setText(_obj->getDataObjectName());
	_ui->comboBox_Material->setCurrentIndex(_obj->getMaterial());
	_ui->checkBox_Initialize_Hydrostatic_Pressure->setChecked(_obj->getInitialize_Hydrostatic_Pressure());
	_ui->doubleSpinBox_Free_Surface0->setValue(_obj->getFree_Surface()[0]);
	_ui->doubleSpinBox_Free_Surface1->setValue(_obj->getFree_Surface()[1]);
	_ui->doubleSpinBox_Free_Surface2->setValue(_obj->getFree_Surface()[2]);
	_ui->doubleSpinBox_Dynamic_Viscosity->setValue(_obj->getDynamic_Viscosity());
	_ui->doubleSpinBox_Kinematic_Viscosity->setValue(_obj->getKinematic_Viscosity());
	_ui->doubleSpinBox_Artificial_Viscosity->setValue(_obj->getArtificial_Viscosity());
}


void GUIDataFluidWidget::on_lineEdit_Name_editingFinished()
{
	_obj->setDataObjectName(_ui->lineEdit_Name->text());

	auto treeOper = Core::FITKOperatorRepo::getInstance()->getOperatorT<EventOper::TreeEventOperator>("ModelTreeEvent");
	if (treeOper != nullptr)
	{
		treeOper->updateTree();
	}
}
void GUIDataFluidWidget::on_comboBox_Material_activated(int index)
{
	_obj->setMaterial(index);
}
void GUIDataFluidWidget::on_checkBox_Initialize_Hydrostatic_Pressure_stateChanged(int state)
{
	_obj->setInitialize_Hydrostatic_Pressure(state);
}
void GUIDataFluidWidget::on_doubleSpinBox_Free_Surface0_valueChanged(double value)
{
	auto d = _obj->getFree_Surface();
	d[0] = value;
	_obj->setFree_Surface(d);
}
void GUIDataFluidWidget::on_doubleSpinBox_Free_Surface1_valueChanged(double value)
{
	auto d = _obj->getFree_Surface();
	d[1] = value;
	_obj->setFree_Surface(d);
}
void GUIDataFluidWidget::on_doubleSpinBox_Free_Surface2_valueChanged(double value)
{
	auto d = _obj->getFree_Surface();
	d[2] = value;
	_obj->setFree_Surface(d);
}
void GUIDataFluidWidget::on_doubleSpinBox_Dynamic_Viscosity_valueChanged(double value)
{
	_obj->setDynamic_Viscosity(value);
}
void GUIDataFluidWidget::on_doubleSpinBox_Kinematic_Viscosity_valueChanged(double value)
{
	_obj->setKinematic_Viscosity(value);
}
void GUIDataFluidWidget::on_doubleSpinBox_Artificial_Viscosity_valueChanged(double value)
{
	_obj->setArtificial_Viscosity(value);
}
